home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Game Programming Gurus / Tricks of the Windows Game Programming Gurus (SAMS)(2000).iso / Articles / AIandBeyond / unroller2.cpp < prev    next >
C/C++ Source or Header  |  1999-05-14  |  1KB  |  35 lines

  1. #include <iostream.h>
  2. #include <math.h>
  3. #include <complex.h>
  4. #include <fstream.h>
  5.  
  6. void main(void)
  7. {
  8.    int k, n;                        // integers for the loops
  9.    complex mult;                    // a complex number
  10.    float prod;                        // a floating point number for the real component
  11.    complex i=complex(0, 1);    // the square root of -1
  12.    fstream file;                    // a file to store the generated source code in
  13.  
  14.    file.open("FFT.C", ios::out);    // opens a text file
  15.     for(k=0; k<512; k++)                // loops through each sub harmonic
  16.    {
  17.         for(n=0; n<1024; n++)        // loops through each sample
  18.       {
  19.           mult=exp((-2*M_PI*i*k*(n+1))/1024);    // calculates the equation
  20.          prod=real(mult);                            // gets the real component
  21.           if(prod!=0)                                    // eliminates useless lines of code
  22.           {
  23.             if(prod!=1)    // only multiplies if the product isn't 1
  24.             {
  25.                 file<<"   Net.Input["<<k<<"]=+X["<<n<<"]"<<"*"<<prod<<";\n";
  26.             }
  27.             else            // prints only the variable because the product is 1
  28.             {
  29.                file<<"   Net.Input["<<k<<"]=+X["<<n<<"];\n";
  30.             }
  31.          }
  32.       }
  33.    }
  34.    file.close();    // closes the file
  35. }